package net.cityside.summer.serivce.impl;

import java.util.List;

import net.cityside.summer.domain.GalleryImg;
import net.cityside.summer.mapper.GalleryImgMapper;
import net.cityside.summer.serivce.IGalleryImgService;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

public class GalleryImgService implements IGalleryImgService {

	private static final Logger logger = Logger
			.getLogger(GalleryImgService.class);

	@Autowired
	private GalleryImgMapper mapper;

	@Override
	public List<GalleryImg> listLatestN(int n) {
		List<GalleryImg> list = mapper.listLatestN(n);
		return list;
	}

	@Transactional
	@Override
	public void save(GalleryImg img) {
		mapper.save(img);
	}

	@Transactional
	@Override
	public void updateTitle(List<GalleryImg> imgs) {
		for (GalleryImg img : imgs) {
			int updated = mapper.updateTitle(img);
			if (updated != 1) {
				logger.warn("更新图片" + img.getFilename() + "，更新了" + updated
						+ "条记录");
			}
		}
	}
}
